package dao

import (
	"system_go/models"
)

func GetAllMembers(membersParam map[string]interface{}) (error, []models.Member, int64) {
	var membersData []models.Member
	page := membersParam["page"].(int)
	pageSize := membersParam["limit"].(int)
	searchName := membersParam["searchName"].(string)
	var total int64
	err := db.Table("member").Where("membername like ? ", "%"+searchName+"%").Order("memberid ASC").Count(&total).Offset((page - 1) * pageSize).Limit(pageSize).Find(&membersData).Error
	return err, membersData, total
}

func AddMembers(members models.Member) error {
	err := db.Table("member").Select("memberid", "membername", "memberphone").Create(&members).Error
	//err := db.Table("member").Create(&members).Error
	return err
}

func DelMembers(id string) error {
	err := db.Table("member").Where("memberid = ?", id).Delete(models.Member{}).Error
	return err
}

func UpdateMembers(members models.Member) error {
	err := db.Table("member").Where("memberid = ?", members.Memberid).Updates(&members).Error
	return err
}
